﻿#include "endingpanel.h"

#include <QPainter>

EndingPanel::EndingPanel(bool isLord,bool isWin, QWidget *parent) : QWidget(parent)
{
    m_bk.load(":/images/gameover.png");
    setFixedSize(m_bk.size());
    m_title=new QLabel(this);
    if(isLord&&isWin)
    {
        m_title->setPixmap(QPixmap(":/images/lord_win.png"));
    }
    else if(isLord&&!isWin)
    {
        m_title->setPixmap(QPixmap(":/images/lord_fail.png"));
    }
    else if(!isLord&&isWin)
    {
        m_title->setPixmap(QPixmap(":/images/farmer_win.png"));
    }
    else if(!isLord&&!isWin)
    {
        m_title->setPixmap(QPixmap(":/images/farmer_fail.png"));
    }
    m_title->move(125,125);
    //分数面板按钮
    m_scorePanel=new ScorePanel(this);
    m_scorePanel->move(75,230);
    m_scorePanel->setFixedSize(260,160);
    //继续游戏按钮-利用样式表美化
    m_continue=new QPushButton(this);
    m_continue->move(84,429);
    connect(m_continue,&QPushButton::clicked,this,&EndingPanel::continueGame);
    //样式表
    QString buttonStyle=R"(
           QPushButton{border-image: url(:/images/button_normal.png)}
           QPushButton:hover{border-image: url(:/images/button_hover.png)}
           QPushButton:pressed{border-image: url(:/images/button_pressed.png)}
            )";
    m_continue->setStyleSheet(buttonStyle);
    m_continue->setFixedSize(231,48);
    //设置字体样式
    m_scorePanel->setMyFontSize(18);
    m_scorePanel->setMyFontColor(ScorePanel::Red);

}

void EndingPanel::setScore(int left, int right, int user)
{
    m_scorePanel->setScores(left,right,user);
}

void EndingPanel::paintEvent(QPaintEvent *ev)
{
    QPainter painter(this);
    painter.drawPixmap(rect(),m_bk);
}
